---
title: 'focused | Cypress Documentation'
description: Get the DOM element that is currently focused in Cypress.
sidebar_label: focused
slug: /api/commands/focused
---

<ProductHeading product="app" />

# focused

Get the DOM element that is currently focused.

## Syntax

```javascript
cy.focused()
cy.focused(options)
```

### Usage

<Icon name="check-circle" color="green" /> **Correct Usage**

```javascript
cy.focused() // Yields the element currently in focus
```

### Arguments

<Icon name="angle-right" /> **options _(Object)_**

Pass in an options object to change the default behavior of `cy.focused()`.

| Option    | Default                                                           | Description                                                                         |
| --------- | ----------------------------------------------------------------- | ----------------------------------------------------------------------------------- |
| `log`     | `true`                                                            | Displays the command in the [Command log](/app/core-concepts/open-mode#Command-Log) |
| `timeout` | [`defaultCommandTimeout`](/app/references/configuration#Timeouts) | Time to wait for `cy.focused()` to resolve before [timing out](#Timeouts)           |

<HeaderYields />

- `cy.focused()` yields the DOM element it found.
- `cy.focused()` is a query, and it is _safe_ to chain further commands.

## Examples

### No Args

#### Get the element that is focused

```javascript
cy.focused().then(($el) => {
  // do something with $el
})
```

#### Blur the element with focus

```javascript
cy.focused().blur()
```

#### Make an assertion on the focused element

```javascript
cy.focused().should('have.attr', 'name', 'username')
```

## Rules

<HeaderRequirements />

- `cy.focused()` requires being chained off a command that yields DOM
  element(s).

<HeaderAssertions />

- `cy.focused()` will automatically [retry](/app/core-concepts/retry-ability)
  until the element(s)
  [exist in the DOM](/app/core-concepts/introduction-to-cypress#Implicit-Assertions).
- `cy.focused()` will automatically [retry](/app/core-concepts/retry-ability)
  until all chained assertions have passed.

<HeaderTimeouts />

- `cy.focused()` can time out waiting for the element(s) to
  [exist in the DOM](/app/core-concepts/introduction-to-cypress#Implicit-Assertions).
- `cy.focused()` can time out waiting for assertions you've added to pass.

## Command Log

**_Make an assertion on the focused element_**

```javascript
cy.focused().should('have.attr', 'name').and('eq', 'num')
```

The commands above will display in the Command Log as:

<DocsImage
  src="/img/api/focused/make-assertion-about-focused-element.png"
  alt="Command Log focused"
/>

When clicking on the `focused` command within the command log, the console
outputs the following:

<DocsImage
  src="/img/api/focused/currently-focused-element-in-an-input.png"
  alt="console focused"
/>

## See also

- [`.blur()`](/api/commands/blur)
- [`.focus()`](/api/commands/focus)
